package com.jia.springcloud.controller;

import com.jia.springcloud.entities.Payment;
import com.jia.springcloud.service.PaymentHystrixService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 1038940655
 * @create 2021/1/22 10:31
 */

@RestController
@Slf4j
@DefaultProperties(defaultFallback = "payment_Global_FallbackMethod")  //全局的，有单独的走单独的，没有单独的就走全局的
public class OrderHystrixController {

    @Autowired
    private PaymentHystrixService paymentHystrixService;

    @RequestMapping("/consumer/hystrix/ok/{id}")
    public Payment getPaymentById(@PathVariable("id") Integer id){
        return paymentHystrixService.getPaymentById(id);
    }

    @RequestMapping("/consumer/hystrix/timeout")
//    @HystrixCommand(fallbackMethod = "fallback",commandProperties = {
//            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "1500")
//    }) 这里可以指定。也可以不指定就走全局的兜底方法
    @HystrixCommand
    public String paymentInfo_TimeOut(){
        return paymentHystrixService.paymentInfo_TimeOut();
    }


//    单个方法的兜底方法
    public String fallback(){
        return "我是消费者8080，支付系统出错，请稍等或者重试";
    }

    //全局兜底方法
    public String payment_Global_FallbackMethod(){
        return "Global异常处理信息，请稍后再试,(┬＿┬)";
    }


}
